import { useTagStore } from "@/store/tags";
export const $addTags = ({ name, path, callback }: any) => {
  const tagStore = useTagStore();
  return tagStore.addTag({ name, path }), callback && callback();
};

export const stringToArray = (str: string) => {
  return (
    (isJSONParse(decodeURIComponent(str)) &&
      JSON.parse(decodeURIComponent(str))) ||
    []
  );
};

export const stringToObject = (str: string) => {
  return (
    (isJSONParse(decodeURIComponent(str)) &&
      JSON.parse(decodeURIComponent(str))) ||
    {}
  );
};

export const objectToString = (array: any) => {
  return encodeURIComponent(JSON.stringify(array));
};

export const createArray = (data: any = false, n: number = 0) => {
  return Array(n).fill(data);
};

export const resetUndefined = (targetForm, originForm) => {
  Object.keys(originForm).forEach((key) => {
    targetForm[key] =
      originForm[key] + "" === "0" ? undefined : originForm[key];
  });
};
